<% layout('/layouts/default.html', {title: '车辆预结算单管理', libs: ['dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">
				<i class="fa icon-notebook"></i> ${text('车辆预结算单管理')}
			</div>
			<div class="box-tools pull-right">
				<a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>

				<a href="#" class="btn btn-default" id="btnSetting" title="${text('设置')}"><i class="fa fa-navicon"></i></a>
			</div>
		</div>
		<div class="box-body">
			<#form:form id="searchForm" model="${tcarPresettlement}" action="${ctx}/settlement/carpresettlement/carPreSettlement/listData" method="post" class="form-inline hide"
					data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
				<div class="form-group">
					<label class="control-label">${text('系统编号')}：</label>
				</div>
				<div class="form-group">
					<label class="control-label">${text('客户')}：</label>
					<div class="control-inline width-160">
						<#form:select path="customerId" items="${customerList}" itemLabel="customerName"
						itemValue="customerId" blankOption="true" class="form-control" onchange="customerChange()"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('服务订单')}：</label>
					<div class="control-inline width-160">
						<#form:select path="serviceOrderId"  items="${serviceOrderList}" itemLabel="serviceOrderCode"
						itemValue="serviceOrderId" blankOption="true" class="form-control" onchange="serviceOrderChange()"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('车架号')}：</label>
					<div class="control-inline width-160">
						<#form:select path="frameNumber" items="${frameNumberList}"
						itemLabel="frameNumber" itemValue="frameNumber" blankOption="true" class="form-control" />
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('车辆名称')}：</label>
					<div class="control-inline">
						<#form:input path="carName" maxlength="100" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('状态')}：</label>
					<div class="control-inline width-120">
						<#form:select path="status" dictType="order_status" blankOption="true" class="form-control isQuick"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('审批状态')}：</label>
					<div class="control-inline width-120">
						<#form:select path="approveStatus" dictType="finance_bill_status" blankOption="true" class="form-control"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('创建者')}：</label>
					<div class="control-inline width-120">
						<#form:select path="createBy" dictType="" blankOption="true" class="form-control"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('创建时间')}：</label>
					<div class="control-inline">
						<#form:input path="createDate_gte" readonly="true" maxlength="20" class="form-control laydate width-date"
							dataFormat="date" data-type="date" data-format="yyyy-MM-dd" data-done="createDate_lte.click()"/>
						&nbsp;-&nbsp;
						<#form:input path="createDate_lte" readonly="true" maxlength="20" class="form-control laydate width-date"
							dataFormat="date" data-type="date" data-format="yyyy-MM-dd"/>
					</div>
				</div>
				<div class="form-group">
					<button type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>
					<button type="reset" class="btn btn-default btn-sm">${text('重置')}</button>
				</div>
			</#form:form>
			<table id="dataGrid"></table>
			<div id="dataGridPage"></div>
		</div>
	</div>
</div>
<% } %>
<script>
	function customerChange() {
		$.ajax({
			type: "POST",
			url: "${ctx}/settlement/carpresettlement/carPreSettlement/getServiceOrderList",
			data: {"customerId": $("#customerId").val(), "createDate_gte" : "", "createDate_lte" : ""},
			success: function (data) {
				$("#serviceOrderId").empty();
				let option = $("<option>").attr({
					"value" : ""}).text("");
				$("#serviceOrderId").append(option);
				if (data.length > 0) {
					for (let i = 0; i < data.length; i++) {
						let partId = data[i].serviceOrderId;
						let partName = data[i].serviceOrderCode;
						let option = $("<option>").attr({
							"value" : partId
						}).text(partName);
						$("#serviceOrderId").append(option);
					}
					$("#serviceOrderId option:first").prop("selected", 'selected');
					$("#serviceOrderId").change();

				}

			}
		});
	}

	function serviceOrderChange() {
		$.ajax({
			type: "POST",
			url: "${ctx}/settlement/carpresettlement/carPreSettlement/getFrameNumberList",
			data: {"serviceOrderId": $("#serviceOrderId").val()},
			success: function (data) {
				$("#frameNumber").empty();
				let option = $("<option>").attr({
					"value" : ""}).text("");
				$("#frameNumber").append(option);
				if (data.length > 0) {

					for (let i = 0; i < data.length; i++) {
						let partId = data[i];
						let partName = data[i];
						let option = $("<option>").attr({
							"value" : partId
						}).text(partName);
						$("#frameNumber").append(option);
					}
					$("#frameNumber option:first").prop("selected", 'selected');
					$("#frameNumber").change();

				}

			}
		});
	}

</script>
<script>
// 初始化DataGrid对象
$('#dataGrid').dataGrid({
	searchForm: $("#searchForm"),
	columnModel: [
		{header:'${text("编码")}', name:'carPresettlementId', index:'a.car_presettlement_id', width:150, align:"left", frozen:true, formatter: function(val, obj, row, act){
			return '<a href="${ctx}/settlement/carpresettlement/carPreSettlement/detail?carPresettlementId='+row.carPresettlementId+'" class="btnList" data-title="${text("编辑车辆预结算单")}">'+(val||row.id)+'</a>';
		}},
		{header:'${text("客户")}', name:'customerName', index:'a.service_order_id', width:150, align:"center"},

		{header:'${text("服务订单")}', name:'serviceOrderId', index:'a.service_order_id', width:150, align:"center"},
		{header:'${text("车架号")}', name:'frameNumber', index:'a.frame_number', width:150, align:"center"},
		{header:'${text("预结算汇率")}', name:'presttlementRate', index:'a.presttlement_rate', width:150, align:"left"},
		{header:'${text("车辆名称")}', name:'carName', index:'a.car_name', width:150, align:"left"},
		{header:'${text("服务订单行号")}', name:'rowNumber', index:'a.row_number', width:150, align:"center"},
		{header:'${text("状态")}', name:'status', index:'a.status', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('order_status')}, val, '${text("未知")}', true);
		}},
		{header:'${text("审批状态")}', name:'approveStatus', index:'a.approve_status', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('finance_bill_status')}, val, '${text("未知")}', true);
		}},
		{header:'${text("操作")}', name:'actions', width:140, sortable:false, title:false, formatter: function(val, obj, row, act){
			var actions = [];
            <% if(hasPermi('settlement:carpresettlement:carPresettlement:view')){ %>
                actions.push('<a href="${ctx}/settlement/carpresettlement/carPreSettlement/detail?carPresettlementId='+row.carPresettlementId+'" class="btnList" title="${text("查看车辆预结算单")}"><i class="fa fa-file-text-o"></i></a>&nbsp;');
            <% } %>
			<% if(hasPermi('settlement:carpresettlement:carPresettlement:delete')){ %>
				actions.push('<a href="${ctx}/settlement/carpresettlement/carPreSettlement/delete?carPresettlementId='+row.carPresettlementId+'" class="btnList" title="${text("删除车辆预结算单")}" data-confirm="${text("确认要删除该车辆预结算单吗？")}"><i class="fa fa-trash-o"></i></a>&nbsp;');
			<% } %>
			return actions.join('');
		}}
	],
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
});

</script>